package com.wd.tw.controller;

import com.wd.common.core.domain.HttpResponse;
import com.wd.tw.service.ElevatorConfigService;
import com.wd.tw.service.ModbusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @className: SignalController
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2025/1/8
 **/

@RestController
@Slf4j
public class SignalController {

    @Resource
    ModbusService modbusService;

    @Resource
    ElevatorConfigService elevatorConfigService;

    /**
     * 给电梯发送信号
     * @param idNum
     * @param status
     * @return
     */
    @RequestMapping("/signal/send")
    public HttpResponse sendSignal(int idNum, boolean status) {
        modbusService.callEle(idNum, status);
        return HttpResponse.success();
    }


    @RequestMapping("/signal/read")
    public HttpResponse getSignal(int offset, int num) {
        boolean[] booleans = modbusService.readState(offset, num);
        return HttpResponse.successData(booleans);
    }

    @RequestMapping("/signalState/refresh")
    public HttpResponse refresh() {
        elevatorConfigService.refreshConfig();
        return HttpResponse.success();
    }


    @RequestMapping("/signalState/read")
    public HttpResponse getSignalState() {
        return HttpResponse.successData(elevatorConfigService.getSignalState());
    }

}
